//
// Created by Hjp22 on 25-7-18.
//

#include "PID_Motor.h"
PID_Motor pid;
float PID_realize(float actual_val)
{
    /*计算目标值与实际值的误差*/
    pid.err = pid.target_val - actual_val;

    /*积分项*/
    pid.integral += pid.err;

    /*PID算法实现*/
    pid.output_val = pid.Kp * pid.err +
                     pid.Ki * pid.integral +
                     pid.Kd * (pid.err - pid.err_last);

    /*误差传递*/
    pid.err_last = pid.err;

    /*返回当前实际值*/
    return pid.output_val;
}

